Skip to content

Use spatial pruning for clash detection and grouping - #280

Merged
mahach666 merged 1 commit into
mainfrom
codex/issue-56-clash-performance
Nov 19, 2026
Merged

mahach666 merged 1 commit into
mainfrom
codex/issue-56-clash-performance

Conversation

@mahach666

Copy link
Copy Markdown
Collaborator

Closes #56.

Changes

  • Use the existing BVH for clash candidates in documents, assemblies and matrix cells. Visit candidates in their original selection order so pair orientation, clash numbering and rule evaluation stay consistent.
  • Reuse transformed vertices within each run, including bounds construction, hard clashes, clearance and duplicate tests. Cull hard-clash triangles outside the shared region while retaining the near-coplanar intersection tolerance and first ten hits.
  • Group nearby clashes through a spatial grid with the existing distance comparison and transitive grouping.

Verification

  • Release build, format verification and native-only build passed. On both .NET 8 and .NET 10, 1,501 tests passed and 12 fixtures were skipped.
  • Synthetic regression tests cover ordered pairs and clash points from a brute-force reference, one transform per mesh for all three narrow-phase modes, near-coplanar contact, matrix clearance at the threshold and transitive grouping.
  • Compared Release .NET 10 builds on Windows against main at 5d06377. Each scene places unit triangles eight units apart along X, with every twentieth pair shifted into overlap. Median of seven runs after two warmups. All four operations returned the same 100, 200 and 400 results or groups, respectively.
Operation 2,000 before → after 4,000 before → after 8,000 before → after
Hard clash, document 22.26 → 2.24 ms 95.78 → 4.36 ms 410.12 → 6.49 ms
Hard clash, assembly 18.82 → 2.29 ms 72.69 → 4.42 ms 347.02 → 8.41 ms
Clash matrix 21.10 → 1.17 ms 87.55 → 2.80 ms 468.48 → 5.77 ms
Proximity grouping 2.56 → 1.59 ms 8.14 → 2.14 ms 46.89 → 4.17 ms

Two meshes with 2,048 triangles each and a single intersecting triangle pair took 463.84 → 0.37 ms. In the early-hit case with coincident meshes, the median was 1.94 → 1.77 ms. Dense overlapping regions still produce many candidate pairs.

@mahach666
mahach666 merged commit 6a697e7 into main Nov 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clash detection scales quadratically: no spatial index in broad phase, all-triangles narrow phase, per-pair world-vertex allocation

1 participant